﻿/*
 
    This file is part of AnkhBG.

    AnkhBG is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    AnkhBG is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with AnkhBG.  If not, see <http://www.gnu.org/licenses/>.
 
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Glider.Common.Objects;

namespace AnkhBG
{
    public class Configuration
    {
        public ConfigForm Window;

        private bool IsWindowOpen
        {
            get
            {
                return (Window != null && !Window.IsDisposed && Window.Visible);
            }
        }

        public void ShowWindow()
        {
            if (Window == null || Window.IsDisposed)
                Window = new ConfigForm();

            if (Settings.Instance.RandomTitles == "true")
                Window.Text = Glider.Common.Objects.GContext.Main.GetRandomString();

            Window.ShowInTaskbar = Settings.Instance.TaskbarHide;            

            Window.Show();
            Window.BringToFront();
        }

        ~Configuration()
        {
            try
            {
                if (GContext.Main != null && GContext.Main.IsGliderRunning)
                    GContext.Main.Debug("AnkhBG: Call: ~Configuration(); Start");
                if (Window != null && Window.IsDisposed)
                    Window.Dispose();
                if (GContext.Main != null && GContext.Main.IsGliderRunning)
                    GContext.Main.Debug("AnkhBG: Call: ~Configuration(); End");
            }
            catch (Exception e)
            {
                if (GContext.Main != null && GContext.Main.IsGliderRunning)
                    GContext.Main.Debug("AnkhBG: Configuration::~Configuration()::Exception: " + e.ToString());
            }
        }
    }
}
